var GroundScript = (function (_super) {

    function GroundScript() {
        GroundScript.super(this);
        this.ground = null;
        this.needDestroy = false;
        this.startRotate = 0;
        this.centerPointRotate = 0;
        this.startAngle = 0;
        this.__moveXX = 0;
        this.__moveYY = 0;
        this.__moveZZ = 0;
        this._xx = 0;
        this._yy = 0;
        this._zz = 0;
        this.life = 120;
    }
    
    Laya.class(GroundScript, "GroundScript", _super);


    GroundScript.prototype._load = function (owner) {
        this.ground = owner;
    }

    /**
     * 脚本帧循环更新
     */
    GroundScript.prototype._update = function (state) {
        if(!this.needDestroy) return;
        this.__moveYY -= (120 - this.life)*0.01
        this._xx += this.__moveXX;
        this._yy += this.__moveYY;
        this._zz += this.__moveZZ;
        var _localPosition = new Laya.Vector3(this._xx,this._yy,this._zz);
        this.ground.transform.localPosition = _localPosition;
        if(this.centerPointRotate > 0){
            this.ground.transform.rotate(new Laya.Vector3(0,0,-1), true, false);
        }else{
            this.ground.transform.rotate(new Laya.Vector3(0,0,1), true, false);
        }
        if(Math.abs(this.centerPointRotate) < 90){
            this.ground.transform.rotate(new Laya.Vector3(1,0,0), true, false);
        }else{
            this.ground.transform.rotate(new Laya.Vector3(-1,0,0), true, false);
        }
        
        this.life--;
        if (this.life < 0) {
            Laya.timer.frameOnce(3, this, function () { this.ground.destroy(); });
        }
    }
    GroundScript.prototype.setBaseData = function (startRotate,startAngle,_yy) {
        this.startRotate = startRotate;
        this.startAngle = startAngle;
        this._yy = _yy;
        
    }
    GroundScript.prototype.destroySelf = function () {
        if(GameSceneObj.isPause) return;
        var directionV3 = new Laya.Vector3();
        //this.startRotate += GameSceneObj.rotateNum;
        var centerPointRotate = this.startRotate - this.startAngle/2;
        while (centerPointRotate > 360) {
            centerPointRotate = centerPointRotate%360;
        }
        while (centerPointRotate < 0) {
            centerPointRotate += 360;
        }
        if(centerPointRotate >= 180){
            centerPointRotate = centerPointRotate - 360
        }
        centerPointRotate*=-1;
        this.centerPointRotate = centerPointRotate;
        var __destroyXX = Math.cos(centerPointRotate*Math.PI / 180) * 200;
        var __destroyYY = -20
        var __destroyZZ = Math.sin(centerPointRotate*Math.PI / 180) * 200;
        this.__moveXX = __destroyXX/Config.GroundDestroyNum;
        this.__moveYY = __destroyYY/Config.GroundDestroyNum;
        this.__moveZZ = __destroyZZ/Config.GroundDestroyNum
        
       
        this.needDestroy = true;
    }
    return GroundScript;
})(Laya.Script);